<?php 
class AlbumModule extends WebModule {
	
	/**
	 * 检测权限
	 * @param int $aid
	 */
	public function checkIdentity($aid, $level = 'guest'){
		if(in_array($level, array('guest', 'author'))){
			$id = $this->id;
			$user = Yii::app()->user;
			$state = $user->getState($id, array());
			return isset($state[$aid][$level]);
		}
		throw new CException('权限参数错误');
	}
	
	
	/**
	 * 设置权限,标志作者或访客
	 * @param string $level author 或者 guest
	 * @param int $aid
	 * @throws CException
	 */
	public function setIdentity($aid, $level){
		if(in_array($level, array('guest', 'author'))){
			$id = $this->id;
			$user = Yii::app()->user;
			$state = $user->getState($id, array());
			$state[$aid] = $level;
			return $user->setState($this->id, $state);
		}
		throw new CException('权限参数错误');
	}
}
?>
